<template>
  <el-container class="bigbox">
    <el-header>
      <div class="logo">
        <h3>黑马头条新闻后台</h3>
      </div>
      <div class="user">
        <img :src="$http.defaults.baseURL+user.head_img" alt />
        <div>{{user.nickname}}</div>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse?'70px':'200px'">
        <el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">
          <div class="btn" @click="toggle">|||</div>
        </el-radio-group>
        <el-menu
          :collapse-transition="false"
          :collapse="isCollapse"
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-menu-item index="/index/list" @click="getPage('/index/list')">
            <i class="el-icon-menu"></i>
            <span slot="title">文章列表</span>
          </el-menu-item>
          <el-menu-item index="/index/publish" @click="getPage('/index/publish')">
            <i class="el-icon-setting"></i>
            <span slot="title">发布文章</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      user: {},
      isCollapse: false
    }
  },
  created() {
    this.user = JSON.parse(localStorage.getItem('user'))
  },
  methods: {
    toggle() {
      this.isCollapse = !this.isCollapse
    },
    getPage(path) {
      if (this.$route.path === path) {
        return
      }
      this.$router.push(path)
    }
  }
}
</script>
<style lang="less" scoped>
.bigbox {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
}
.el-aside {
  background: #545c64;
}
.el-header {
  background: #2b343d;
  display: flex;
  color: #fff;
  justify-content: space-between;
  align-items: center;
}
/deep/ .el-menu {
  border: none;
}
.logo {
  h3 {
    height: 60px;
    line-height: 60px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    background: #2b343d;
  }
}
.user {
  margin-right: 30px;
  display: flex;
  img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 50%;
    margin-right: 10px;
  }
  div {
    color: #fff;
    align-self: center;
  }
}
.el-radio-group {
  width: 100%;
  margin: 0 !important;
  cursor: pointer;
  .btn {
    height: 50px;
    line-height: 50px;
    background: orange;
    width: 100%;
    font-size: 14px;
    text-align: center;
  }
}
</style>